﻿using IdentityServer4;
using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication_IdentityServer4_SampleTest
{
    public class IdentityServerConfig
    {
        public static IEnumerable<ApiResource> GetApiResources()
        {
            List<ApiResource> apis = new List<ApiResource>();
            apis.Add(new ApiResource("sendEmail", "apiEmail显示名字")
            {
                Scopes = { "sendEmail" },
            });

            apis.Add(new ApiResource()
            {
                Name = "sendMessage",
                DisplayName = "apiMessage",
                Scopes = { "sendMessage" },
            });

            return apis;
        }

        public static IEnumerable<Client> GetClients()
        {
            List<Client> cLs = new List<Client>();
            cLs.Add(new Client
            {
                ClientId = "android",
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                ClientSecrets = { new Secret("12345".Sha256()) },
                AllowedScopes = { "sendEmail", IdentityServerConstants.StandardScopes.OpenId,
                 IdentityServerConstants.StandardScopes.Profile},
                AllowOfflineAccess=true,
            });;

            return cLs;
        }

        public static IEnumerable<ApiScope> ApiScopes =>
        new ApiScope[]
        {
            new ApiScope("sendEmail"),
            new ApiScope("sendMessage"),
        };

        public static IEnumerable<IdentityResource> GetIdentityResource()
        {

            return new List<IdentityResource>()
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),

            };
        }

        
    }
}
